package com.book.oauth.server.user.hystrix.impl;

import com.book.common.api.entity.CurrentUser;
import com.book.common.api.helper.LanguageHelper;
import com.book.common.result.Failed;
import com.book.common.result.RestResponse;
import com.book.oauth.server.user.dto.UserDto;
import com.book.oauth.server.user.hystrix.IOauthHystrix;
import com.book.oauth.server.user.vo.CurrentUserDetail;
import com.book.oauth.server.user.vo.UserVo;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Description：IOauthToken熔断器
 *
 * @Author： leo.xiong
 * @CreateDate： 2019/10/14 15:25
 * @Email： leo.xiong@suyun360.com
 * Version：1.0
 */
@Slf4j
@Component
public class OauthHystrixImpl implements FallbackFactory<IOauthHystrix>, IOauthHystrix {

    @Override
    public IOauthHystrix create(Throwable e) {
        log.error("服务调用异常", e.getMessage());
        e.printStackTrace();
        return new OauthHystrixImpl();
    }

    @Override
    public RestResponse<CurrentUser> getPrincipal(String token) {
        log.error("调用oauth-server.getPrincipal服务getPrincipal方法失败!");
        return new Failed("BOOK:COMMON:10018", "OauthHystrixImpl.getPrincipal" + LanguageHelper.getValue("BOOK:COMMON:10018"));
    }

    @Override
    public RestResponse<CurrentUserDetail> getCurrentUserDetail(CurrentUser currentUser) {
        log.error("调用oauth-server.getCurrentUserDetail方法失败!");
        return new Failed("BOOK:COMMON:10017", "OauthHystrixImpl.getCurrentUserDetail" + LanguageHelper.getValue("BOOK:COMMON:10018"));
    }

    @Override
    public Map<String, String> getOauthToken(String username, String password, String client_id, String client_secret, String grant_type, String scope) {
        log.error("调用oauth-server.getOauthToken方法失败!");
        return null;
    }

    @Override
    public RestResponse<String> logout(String token) {
        log.error("调用oauth-server.logout方法失败!");
        return new Failed("BOOK:COMMON:10018", "OauthHystrixImpl.logout" + LanguageHelper.getValue("BOOK:COMMON:10018"));
    }

    @Override
    public RestResponse<UserVo> registered(UserDto userDto) {
        log.error("调用oauth-server.logout方法失败!");
        return new Failed("BOOK:COMMON:10018", "OauthHystrixImpl.registered" + LanguageHelper.getValue("BOOK:COMMON:10018"));
    }
}
